<!DOCTYPE html>
<html 	xmlns="http://www.w3.org/1999/xhtml"
		xmlns:th="http://www.thymeleaf.org"
	 	xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
  		layout:decorator="app/layout/layout"
  		xmlns:dt="http://github.com/dandelion/datatables">

<head >
	<meta charset="utf-8" />
	<title>Listado de mis Módulos</title>
</head>

<body>
	<section layout:fragment="content">
		<div class="container">
			<br /> <br />
			<form id="grillaForm" th:object="${grillaModulos}"
				class="custom-form" th:action="@{'/modulos/nuevo'}"
				th:method="@{'POST'}">
				
				<input type="hidden" th:id="@{'moduloId'}" th:name="@{'moduloId'}" value=""/>

				<div class="panel panel-primary lg">

					<div class="panel-heading">Listado de Módulos</div>

					<div class="table-responsive">
						<table id="tablaModulosId" dt:table="true"
							class="table table-striped" dt:dom="'t'">
							<thead>
								<tr>
									<th th:text="@{'Acciones'}"></th>
									<th th:text="@{'Nombre'}"></th>
									<th th:text="@{'Descripcion'}"></th>
									<th th:text="@{'Fecha de Inicio'}"></th>
									<th th:text="@{'Fecha Fin'}"></th>
								</tr>
							</thead>
							<tbody>
								<tr class="odd"
									th:if="${#lists.isEmpty(grillaModulos)}">
									<td class="dataTables_empty" valign="top" colspan="8"
										th:text="${'No se encontraron Datos!'}"></td>
								</tr>
								<tr th:each="x, rowStat : ${grillaModulos}">
									<td align="center" width="20%">
										<button type="button" class="btn btn-primary" name="edit" title="Editar Módulo"
											th:value="${rowStat.index}" th:onclick="'editar(\'' + ${x.id} + '\')'"
											data-th-alt="Editar"
											th:if="${x.fechaFin == null}"><span class="glyphicon glyphicon-edit"></span></button>
<!-- 									<button type="submit"  class="btn btn-default" name="print" th:value="${rowStat.index}" th:text="Imprimir" th:if="${x.estado.abreviatura == 'PEND'}">Imprimir</button> -->

										<button type="submit" class="btn btn-primary" name="print" title="Generar PDF e Imprimir"
											th:onclick="'printReport(\'' + ${x.id} + '\')'" id="printBtn"
											data-th-alt="Imprimir"
											th:if="${x.fechaFin == null}"><span class="glyphicon glyphicon-print" data-th-alt="Imprimir"></span></button>
										
										<button type="submit" class="btn btn-info" name="view" title="Visualizar Módulo"
											th:value="${rowStat.index}" th:onclick="'showEditModal(\'' + ${x.id} + '\',\'' + ${x.nombre} + '\',\'' +${x.descripcion} +'\')'"
											data-toggle="modal" data-target="#motivoPresentacionModal" data-th-alt="Ver"
											><span class="glyphicon glyphicon-eye-open"></span></button>
										
										<button type="button" class="btn btn-danger" name="delete" title="Eliminar Módulo"
											th:value="${rowStat.index}" th:onclick="'eliminar(\'' + ${x.id} + '\')'"
											data-th-alt="Eliminar"
											th:if="${x.fechaFin == null}"><span class="glyphicon glyphicon-trash"></span></button>
											
		
									</td>
									
									
									<td th:text="${x.nombre}"></td>
									<td th:text="${x.descripcion}"></td>
									<td th:text="${x.fechaInicio != null ? #calendars.format(x.fechaInicio,'dd/MM/yyyy') : ''}"></td>
									<td th:text="${x.fechaFin != null ? #calendars.format(x.fechaFin,'dd/MM/yyyy') : ''}"></td>
<!-- 									<td class="right" -->
<!-- 										th:text="${#numbers.formatDecimal(x.importeTotal, 0, 'COMMA', 2, 'POINT')}"></td> -->
								</tr>
							</tbody>
							<tfoot>
								<tr>
									<td th:align="right" colspan="5">
										<!-- 						   			<a class="btn btn-primary" role="button" name="new"  -->
										<!-- 							th:if="${#lists.isEmpty(grillaProyectos.proyectos)} or ${!grillaProyectos.pending}" -->
										<!-- 							th:href="@{'/base/admin/grilla/new'}">Cargar Nuevo Proyecto</a> -->
										<button id="nuevaPresBtn" class="btn btn-primary"
											type="submit"
											th:align="right">Cargar Nuevo Módulo</button>
									</td>
								</tr>
							</tfoot>
						</table>
						<div class="right">

						</div>
					</div>
				</div>

			</form>
		</div>

			
	</section>
	<footer>
		<section layout:fragment="custom-footer">
			<script th:src="@{/js/jquery.fnReloadAjax.js}"></script>
			<script th:src="@{/js/jquery.validate.min.js}"></script>
			<script th:src="@{/js/additional-methods.min.js}"></script>
			<script th:src="@{/js/select2.min.js}"></script>
			<script th:src="@{/js/wysihtml5-0.3.0.js}"></script>
			<script th:src="@{/js/bootstrap-wysihtml5.js}"></script>
			<script th:src="@{/js/ckeditor.js}"></script>
			<script th:src="@{/js/bootstrap-markdown.js}"></script>
			<script th:src="@{/js/markdown.js}"></script>
			<script th:src="@{/js/jquery.inputmask.js}"></script>
			<script th:src="@{/js/jquery.inputmask.numeric.extensions.js}"></script>
			<script th:src="@{/js/jquery.inputmask.regex.extensions.js}"></script>
			
			<script type="text/javascript">
			
				function editar(moduloId){
					var frm = $('#grillaForm');
					frm.attr('action', '/sisale/modulos/editar-modulo');
					$('#moduloId').val(moduloId);
					frm.submit();
				}

				function eliminar(moduloId){
					if (confirm('Esta seguro de querer eliminar el registro?')){
						var frm = $('#grillaForm');
						frm.attr('action', '/sisale/modulos/eliminar');
						$('#moduloId').val(moduloId);
						frm.submit();
					} else{
						return false;
					}
				}
	
				function printReport(moduloId){
					var frm = $('#grillaForm');
					frm.attr('action', '/app/imprimir-reporte-modulos');
					$('#moduloId').val(moduloId);
					frm.submit();
				} 

			</script>
		</section>
	</footer>
</body>
</html>